from quote.base.browser_operation import BrowserOP
from quote.base.use_browser import UseBrowser
from quote.util.excel_op import ExcelOp
from quote.util.yamlOp import YamlOp


class LoginPage:
    def __init__(self):
        self.ub = UseBrowser()
        self.a = BrowserOP(UseBrowser.driver)
        self.exl = ExcelOp()
        self.yo = YamlOp()
        self.exl.get_sheet('登录用例参数')

    def login(self,username,passwd):  #登录功能
        self.a.open_url(self.exl.get_cell(1,1))
        self.a.input_text('name', self.yo.get_locator('LoginPage','username'), username)
        self.a.input_text('name', self.yo.get_locator('LoginPage','password'), passwd)
        self.a.click('name',self.yo.get_locator('LoginPage','submit'))

    def login_suc_info(self):       #获取登录成功的信息
        self.a.change_frame('main')
        suc_info = self.a.get_text('xpath',self.yo.get_locator('LoginPage','suc_info'))
        return suc_info

    def login_fail_info(self):   #获取登录失败的信息
        fail_info = self.a.get_text('xpath', self.yo.get_locator('LoginPage','fail_info'))
        return fail_info

# if __name__ == '__main__':
#     lp =LoginPage()
#     lp.login('admin','admin')